/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package FileManager;

import Data.Data;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Riso-Desktop
 */
public class FileManager {

    String nazov = "";

    public FileManager(String nazov) {
        this.nazov = nazov;
    }


    public boolean zapis(Object o) {
        try {
            FileOutputStream fos = new FileOutputStream(nazov+".dat");
            ObjectOutputStream oos = new ObjectOutputStream(fos);

            oos.writeObject(o);
            oos.flush();
            oos.close();
            return true;
        } catch (IOException ex) {
            Logger.getLogger("mojlog").log(Level.WARNING,ex.toString(),ex);
            return false;
        }
    }

    public Data citajData() {
        Data data= null;
        try {
            FileInputStream fis = new FileInputStream(nazov+".dat");
            ObjectInputStream ois = new ObjectInputStream(fis);
            
            data = (Data) ois.readObject();
            ois.close();
            return data;
        } catch (Exception ex) {
            Logger.getLogger("mojlog").log(Level.WARNING,ex.toString(),ex);
            return null;
        }
    }
}
